package cn.org.donald.framework.util;

import cn.org.donald.framework.handler.ServiceException;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;

/**
 * @author : Donald
 * @since : 2020/11/16 16:58
 */
public class StringUtil extends StringUtils {

    private static final String verifyPhone = "^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";

    /**
     * 隐藏大陆手机
     * @param phone
     * @return
     */
    public static String hideMainlandPhone(String phone){
        try {
            if (phone.matches(verifyPhone)){
                return phone.substring(0,3) + "****" + phone.substring(7,11);
            }else {
                throw new IllegalAccessException("This phone can not format, it is not a Chinese Mainland phone number!");
            }
        }catch (IllegalAccessException e){
            e.printStackTrace();
            throw new ServiceException(HttpStatus.INTERNAL_SERVER_ERROR.value(),"系统错误!");
        }

    }
}
